package sicnu.cs.aps.common.enums;

import org.apache.commons.lang.StringUtils;

import java.util.NoSuchElementException;

/**
 * @author CaiKe
 */
public enum FileTypeEnum {
    // 上传文件前缀字段
    CERT("aps/avatar/", "用户头像"),
    BLOG("aps/blog/", "博客中的图片"),
    ACTIVITY_PLAN_ATTACHMENT("aps/plan/", "填写活动策划的附件"),
    ATTACHMENT("aps/attachment/", "创建活动的附件"),
    AUDIT("aps/audit/", "审核时的附件"),
    ;


    String value;
    String description;

    FileTypeEnum() {
    }

    FileTypeEnum(String value, String description) {
        this.value = value;
        this.description = description;
    }

    public String getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "ConfigEnum{" +
                "value='" + value + '\'' +
                "} " + super.toString();
    }

    public static FileTypeEnum toEnum(String value) {
        if (StringUtils.isEmpty(value))
            throw new IllegalArgumentException("value不能为空或null");

        for (FileTypeEnum configEnum : FileTypeEnum.values()) {
            if (configEnum.getValue().equals(value)) {
                return configEnum;
            }
        }
        throw new NoSuchElementException("无 " + value + " 对应的ConfigEnum");
    }

}
